//
//  SEGraphicalIntroductionView.swift
//  SmartEyeForPatient
//
//  Created by QDSG on 2021/4/7.
//

import UIKit

class SEGraphicalIntroductionView: UIView {

    @IBOutlet private weak var contentView: UIView! {
        didSet {
            contentView.setLayerCorners(rect: contentView.bounds,
                                        radius: 12,
                                        corners: [.topLeft, .topRight])
        }
    }
    
    @IBOutlet private weak var backgroundView: UIView! {
        didSet {
            let tapGesture = UITapGestureRecognizer(target: self, action: #selector(_dismissMenu))
            backgroundView.addGestureRecognizer(tapGesture)
        }
    }
    
    @IBOutlet private weak var contentViewBottomConstraint: NSLayoutConstraint!
    
    @IBAction private func backButtonAction() {
        dismiss()
    }
    
    func show() {
        self.frame = UIScreen.main.bounds
        UIApplication.shared.keyWindow?.addSubview(self)
        
        contentViewBottomConstraint.constant = 0.0
        
        UIView.animateKeyframes(withDuration: 0.25, delay: 0, options: .calculationModeLinear) {
            self.layoutIfNeeded()
        } completion: { _ in
            
        }
    }
    
    @objc private func _dismissMenu() {
        dismiss()
    }
    
    func dismiss() {
        contentViewBottomConstraint.constant = -220.0
        
        UIView.animateKeyframes(withDuration: 0.25, delay: 0, options: .calculationModeLinear) {
            self.layoutIfNeeded()
        } completion: { _ in
            self.removeFromSuperview()
        }
    }
}
